import geopandas as gpd
import pandas as pd
import os
## find the directory of the python (assures compatibility)
python_directory = os.path.abspath("")
from tqdm import tqdm
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
import folium
import copy
import math
import statistics
import numpy as np
import warnings
warnings.filterwarnings("ignore")
from models import Optimise_PANs_LSOAs, Optimise_PANs_Schools, Optimise_PANsCatchment_Schools, Optimise_PANsCatchment_LSOAs, reset_parameters, create_custom_legend_handles
This includes adding the information required for models in the analysis phase. This includes the estimated number of 5 year olds:
## load the PANs
PANs = pd.read_csv(rf"{python_directory}/data/Yr7_admissions.csv")
## load the maps
schools = gpd.read_file(rf"{python_directory}/data/brighton_sec_schools.geojson")
lsoa = gpd.read_file(rf"{python_directory}/data/BrightonLSOA_Clean.geojson")
students = gpd.read_file(rf"{python_directory}/data/BrightonLSOA_Clean.geojson")
catchment_a = gpd.read_file(rf"{python_directory}/data/catchment_01.geojson")
catchment_b = gpd.read_file(rf"{python_directory}/data/catchment_02.geojson")
catchment_c = gpd.read_file(rf"{python_directory}/data/catchment_03.geojson")
catchment_list = [catchment_a, catchment_b, catchment_c]
## transform lsoa and students dataframes to EPSG:27700 (For the UK)
lsoa.to_crs(epsg="27700", inplace=True)
students.to_crs(epsg="27700", inplace=True)
for catchment in catchment_list:
catchment["geometry"] = catchment.buffer(0)
catchment.to_crs(epsg="27700", inplace=True)
## Print the current CRS
print(f"CRS | schools = {schools.crs}, LSOA = {lsoa.crs}, students LSOA = {students.crs}")
CRS | schools = EPSG:27700, LSOA = EPSG:27700, students LSOA = EPSG:27700
## define colours
colours = {
"Blatchington Mill School": "steelblue",
"Brighton Aldridge Community Academy": "orange",
"Cardinal Newman Catholic School": "limegreen",
"Dorothy Stringer School": "firebrick",
"Hove Park School and Sixth Form Centre": "mediumpurple",
"King's School": "sienna",
"Longhill High School": "palevioletred",
"Patcham High School": "gray",
"Portslade Aldridge Community Academy": "darkkhaki",
"Varndean School": "darkturquoise",
}
## assign school colours
schools["colour"] = [colours[schools.at[i, "establishment_name"]] for i in schools.index]
## Calculate the estimated 5 year students
reset_parameters(catchment_a, schools, students)
## Generate interactive map for the number of 5 year olds
m = students.explore(column="5_est", tooltip="5_est", name="Estimated 5 year olds", legend=True, min_zoom=12)
schools.explore(
m=m, column="establishment_name", tooltip="establishment_name", color=schools["colour"], name="Schools",
marker_kwds={"radius": 5}, style_kwds={"fillOpacity":1}, legend=True
)
display(m)
m = None
We consider the three catchment zone alternatives (labelled "Catchment alternative 1", "Catchment alternative 2" and "Catchment alternative 3" in the layers of the plotted map). Each LSOA is assigned to the catchment zone which contains the majority of the LSOA. This leads to cases where the LSOA catchment zones do not strictly align with the drawn catchment zones (as the drawn catchment zones do not strictly follow the outlines of LSOAs)
## Plot interactive map for all the three catchments
reset_parameters(catchment_a, schools, students)
m = students.explore(column="catchment_ID", categorical=True, cmap="tab10", tooltip="catchment_ID", legend=False, name=f"LSOA alternative 1", min_zoom=12)
catchment_a.explore(m=m, tooltip="catchment_ID", style_kwds={"fill": False, "color": "black"}, name=f"Catchment alternative 1")
reset_parameters(catchment_b, schools, students)
students.explore(m=m, column="catchment_ID", categorical=True, cmap="tab10", tooltip="catchment_ID", legend=False, name=f"LSOA alternative 2")
catchment_b.explore(m=m, tooltip="catchment_ID", style_kwds={"fill": False, "color": "black"}, name=f"Catchment alternative 2")
reset_parameters(catchment_c, schools, students)
students.explore(m=m, column="catchment_ID", categorical=True, cmap="tab10", tooltip="catchment_ID", legend=False, name=f"LSOA alternative 3")
catchment_c.explore(m=m, tooltip="catchment_ID", style_kwds={"fill": False, "color": "black"}, name=f"Catchment alternative 3")
schools.explore(
m=m, column="establishment_name", tooltip="establishment_name", color=schools["colour"], name="Schools",
marker_kwds={"radius": 5}, style_kwds={"fillOpacity":1}, legend=False
)
folium.LayerControl().add_to(m)
print("All catchment alternatives overlayed (hide layers in interactive map)")
display(m)
m=None
All catchment alternatives overlayed (hide layers in interactive map)